const handler = require('./handler.js')

const core = async (conn , msg)=>{
	console.log(msg)
	let split = msg.split(' ')
	console.log(split)
	let method = split[0],value = split[1]?split[1]:''

	if(!handler[method]){
		return `没有该操作${method}`
	}
	let result
	await handler[method](conn,value,(data)=>{
		result = data
	})
	return result;
}

exports.core = core
exports.getData = handler.getDataHandle
// 测试
if (require.main === module) {
	var client = require('./handler.js')
	console.log(client);
	client=client.connect({connect:'127.0.0.1:2181',sessionTimeout:5000});
	// ({connect:'127.0.0.1:2181',sessionTimeout:5000})
	
	// let zk1 = require('./zkclient.js');
	(async ()=>{
		let [err,data] = await client.getData('/test')
		console.log(err,data)
	})()
}